package com.seed.web.struts.sysmanager;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.seed.commons.dbquery.PageViewForSQL;
import com.seed.service.sysmanager.IInsideUser;
import com.seed.web.core.BaseActionSupport;
import com.seed.web.form.sysmanager.InsideUserForm;

@Controller
@Scope("prototype")
public class InsideUserAction extends BaseActionSupport {

	private static final long serialVersionUID = 1L;

	private InsideUserForm user;
	
	private String[] roleids ;

	public String[] getRoleids() {
		return roleids;
	}

	public void setRoleids(String[] roleids) {
		this.roleids = roleids;
	}

	public InsideUserForm getUser() {
		return user;
	}

	public void setUser(InsideUserForm user) {
		this.user = user;
	}

	@Resource(name = "pageViewForSQL")
	private PageViewForSQL pv;

	public PageViewForSQL getPv() {
		return pv;
	}

	public void setPv(PageViewForSQL pv) {
		this.pv = pv;
	}

	@Resource
	private IInsideUser insideUserService;

	public String updateUser() throws Exception {
		
		return "" ;
	}
	
	public String setUserRoles() throws Exception {
		if(null != user && null != roleids && roleids.length > 0) {
			if(this.insideUserService.setUserRole(user.getUserId(), roleids)) {
				saveMessage("为用户分配角色成功！");
			} else {
				saveMessage("为用户分配角色失败！");
			}
		} else {
			saveMessage("发生错误，请选择角色！");
		}
		
		return "msg" ;
	}
	
	public String saveUser() throws Exception {
		boolean flag = this.insideUserService.saveInsideUser(user);
		if (flag) {
			saveMessage("用户添加成功！");
		} else {
			saveMessage("用户添加 失败！");
		}
		return "msg";
	}

	public String findUser() throws Exception {
		pv.setPageModel(this.insideUserService.getScrollData(pv.getFirstResult(),
				pv.getLineSize()));
		
		this.getBaseform().getRequest().setAttribute("scrolldata", pv);
		return "finduser";
	}
}
